//引入插件：微信同声传译
const plugin = requirePlugin('WechatSI');
//创建内部 audio 上下文 InnerAudioContext 对象。
const innerAudioContext = wx.createInnerAudioContext();
innerAudioContext.onError(function (res) {
  console.log(res);
  wx.showToast({
    title: '语音播放失败',
    icon: 'none',
  })
})
const wordYun = (content) => {
  let mute = wx.getStorageSync('mute')
  if (mute == false) { //读取缓存，判断是否静音
    plugin.textToSpeech({
      lang: "zh_CN",
      content: content,
      success: function (res) {
        // console.log(res);
        // console.log("音频保存地址:", res.filename);
        //播放语音
        if (res.filename == '') {
          console.log('暂无语音');
          return;
        }
        innerAudioContext.src = res.filename //设置音频地址
        innerAudioContext.play(); //播放音频
      },
      fail: function (res) {
        console.log("fail tts", res)
      }
    })

  } else {
    console.log(`已静音,内容：${content}`);
  }
}
export default {
  wordYun
}